using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace ns
{
    ///<summary>
    ///
    ///</summary>
    public class CreatePrefabConfig : Editor
    {
        static string t= "prefab";
        static string respath= "Assets/Resources";
        [MenuItem("Tools/Resources/Create Prefab Config")]
        public static void Create()
        {
            string[] resFiles = AssetDatabase.FindAssets("t:"+t, new string[]{respath});
            for (int i = 0; i < resFiles.Length; i++) 
            {
                resFiles[i] = AssetDatabase.GUIDToAssetPath(resFiles[i]);
                string fileName = Path.GetFileNameWithoutExtension(resFiles[i]);
                string filePath = resFiles[i].Replace(respath+"/",string.Empty).Replace("."+t,string.Empty);
                resFiles[i] = fileName+"="+filePath;
            }
            string url;
            string filename = "PrefabConfigMap.txt";
            #region
#if UNITY_EDITOR
            url = Application.dataPath + "/StreamingAssets/" + filename;
#elif UNITY_WINDOW
            url = Application.dataPath + "/StreamingAssets/"+filename;            
#elif UNITY_IOS
            url = Application.dataPath + "/Raw/"+filename; 
#elif UNITY_ANDROID
            url = Application.dataPath + "!/assets/"+filename; 
#endif
            #endregion
            File.WriteAllLines(url, resFiles);
            AssetDatabase.Refresh();
        }
    }
}
